package ru.usu.gv.gui.analysis;

import ru.usu.gv.core.GraphEngine;
import ru.usu.gv.gui.component.GVSlider;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import java.awt.Color;

/**
 @author Sergey Pupyrev 
 12.04.2007
 */

public class AnalysisPanel extends JPanel
{
	private static AnalysisPanel INSTANCE = new AnalysisPanel();

	public static AnalysisPanel getInstance()
	{
		return INSTANCE;
	}

	private JPanel commonStatisticsPanel;
	private GVSlider uniformEdgeSlider;
	private GVSlider vertexDistanceSlider;
	private GVSlider bendSlider;
	private GVSlider angleSlider;
	private GVSlider volumeSlider;
	private GVSlider ortogonalSlider;
	private GVSlider crossingSlider;

	private AnalysisPanel()
	{
		setVisible(false);
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		TitledBorder border = new TitledBorder("Анализ графа");
		border.setTitlePosition(TitledBorder.TOP);
		border.setTitleJustification(TitledBorder.CENTER);
		border.setTitleColor(Color.RED);
		setBorder(border);

		commonStatisticsPanel = new JPanel();
		add(commonStatisticsPanel);

		uniformEdgeSlider = new GVSlider("Унификация длины ребер", 0, 100, 0, false);
		add(uniformEdgeSlider);

		vertexDistanceSlider = new GVSlider("Расстояние между вершинами", 0, 100, 0, false);
		add(vertexDistanceSlider);

		bendSlider = new GVSlider("Сгибы на ребре", 0, 100, 0, false);
		add(bendSlider);

		angleSlider = new GVSlider("Угол между ребрами", 0, 100, 0, false);
		add(angleSlider);

		volumeSlider = new GVSlider("Область размещения", 0, 100, 0, false);
		add(volumeSlider);

		ortogonalSlider = new GVSlider("Ортогональность", 0, 100, 0, false);
		add(ortogonalSlider);

		crossingSlider = new GVSlider("Пересечение ребер", 0, 100, 0, false);
		add(crossingSlider);
	}

	public void changeVisibleState()
	{
		if (isVisible())
		{
			setVisible(false);
			GraphEngine.getInstance().getAnalysBehavior().setVisible(false);
			GraphEngine.getInstance().getAnalysUIBehavior().setVisible(false);
		}
		else
		{
			setVisible(true);
			GraphEngine.getInstance().getAnalysBehavior().setVisible(true);
			GraphEngine.getInstance().getAnalysBehavior().setEnabledInternal();
			GraphEngine.getInstance().getAnalysUIBehavior().setVisible(true);
			GraphEngine.getInstance().getAnalysUIBehavior().setEnabledInternal();
		}
	}

	public JPanel getCommonStatisticsPanel()
	{
		return commonStatisticsPanel;
	}

	public GVSlider getUniformEdgeSlider()
	{
		return uniformEdgeSlider;
	}

	public GVSlider getVertexDistanceSlider()
	{
		return vertexDistanceSlider;
	}

	public GVSlider getBendSlider()
	{
		return bendSlider;
	}

	public GVSlider getAngleSlider()
	{
		return angleSlider;
	}

	public GVSlider getVolumeSlider()
	{
		return volumeSlider;
	}

	public GVSlider getOrtogonalSlider()
	{
		return ortogonalSlider;
	}

	public GVSlider getCrossingSlider()
	{
		return crossingSlider;
	}
}
